//! \file hexa.hpp
//! \brief Purewell Library Hexa Encoder/Decoder Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2009-11-26

#ifndef __PWHDR_HEXA_HPP__
#define __PWHDR_HEXA_HPP__

namespace purewell
{

//! \brief Hexa encoder/decoer
class PWAPI PWHexa
{
public:
	//! \brief Encode stream.
	//! \param[out] os Output stream.
	//! \param[in] is Input stream.
	//! \param[in] cap Use capital characters.
	//! \return Output stream reference.
	std::ostream& encode(std::ostream& os, std::istream& is,
		bool cap = true) const;

	//! \brief Encode block.
	//! \param[out] obuf Output buffer. It's would be 2 times of input
	//! buffer length.
	//! \param[in] ibuf Input buffer.
	//! \param[in] iblen Input buffer length.
	//! \param[in] cap Use capital characters.
	//! \return Output buffer length.
	size_t encode(char* obuf, const char* ibuf, size_t iblen,
		bool cap = true) const;

	//! \brief Decode stream.
	//! \param[out] os Output stream.
	//! \param[in] is Input stream.
	//! \return Output stream reference.
	std::ostream& decode(std::ostream& os, std::istream& is) const;

	//! \brief Decode block.
	//! \param[out] obuf Output buffer.
	//! \param[in] ibuf Input buffer.
	//! \param[in] iblen Input buffer length.
	//! \return Output buffer length.
	size_t decode(char* obuf, const char* ibuf, size_t iblen) const;

	//! \brief Encode unit.
	//! \param[out] o Encoded characters.
	//! \param[in] c Source character.
	//! \param[in] cap Use capital-alphabet.
	//! \return Encoded character pointer.
	char* encode(char o[2], char c, bool cap) const;

	//! \brief Decode unit.
	//! \param[in] o Encoded character.
	//! \return Decoded character.
	char decode(const char o[2]) const;

public:
	//! \brief Get instance.
	//! \return Instance reference.
	static PWHexa& getInstance(void);

private:
	explicit PWHexa();
	inline PWHexa& operator = (const PWHexa&) { return *this; }

};

//! \brief Global Hexa encoder/decoder instance.
extern PWAPI PWHexa& gPWHexa;

};//namespace purewell

#endif//!__PWHDR_HEXA_HPP__

